package com.my.rabbitmq.two;

import com.my.utils.RabbitMQUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @author 林允
 * @version 1.0
 * @description: TODO
 * @date 2023/11/24 22:56
 */

//工作线程2
public class Worker02 {

    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) {

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("consumerTag = " + consumerTag);
            byte[] body = message.getBody();
            System.out.println(new String(body));
        };

        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println("consumerTag = " + consumerTag);
        };

        try {
            Channel channel = RabbitMQUtils.getChannel();
            System.out.println("C2等待消息");
            channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
